//
// Created by Administrator on 2021/10/18.
//
#include <iostream>

class Solution {
public:
    int findComplement(int num) {
        int highbit = 0;
        for (int i = 1; i <= 30; ++i) {
            if (num >= (1 << i)) {
                highbit = i;
            }
            else {
                break;
            }
        }
        int mask = (highbit == 30 ? 0x7fffffff : (1 << (highbit + 1)) - 1);
        return num ^ mask;


    }
};

int main() {
    Solution solution;
    std::cout << solution.findComplement(7) << std::endl;
    return 0;
}